package manager;


import java.util.ArrayList;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import org.hibernate.Session;

import sessionHibernate.HibernateUtil;
import bean.Client;
import bean.Voyage;


@ManagedBean
@SessionScoped
public class Manager {

	Session sessionHibernate = null;
	String err = "";
	boolean logged = false;
	private Client client;
	private List <Voyage> voyages = null;

	private List <String> srceVilles = new ArrayList<String>();
	private List <String> destVilles = new ArrayList<String>();
	
	private ArrayList <String> messagesPage = new ArrayList<String>();
	private ArrayList <String> messagesErr = new ArrayList<String>();
	
	private Integer idVoyage = null;
	
//	public List<String> listePays(String prefix) {
//		  
//		   ArrayList<String> result = new ArrayList<String>();
//		   result.add("England");
//		   result.add("France");
//		   result.add("Germany");
//		   result.add("Italy");
//		   result.add("Spain");
//		 
//		   return result;
//		  }
//	private String pays ;
	
	 


	public Manager()  {
		sessionHibernate =  HibernateUtil.getSession();
		client = new Client();
	
		srceVilles.add("Brest");
		srceVilles.add("Quimper");

		
	}

	public String process() {
		System.out.println("Manager process");
		messagesErr.add("Manager process");
		return "accueil";
	}
	
	public String loginAction() {
		Client c = Base.getClient(client.getLogin(), sessionHibernate);
		
		System.out.println("nom = "+client.getNom());
		if(c == null){
			logged = false;
			messagesErr.add("Identification impossible");
			messagesErr.add("Compte inexistant");
			return "identification";
		}
		
		if (c.getPassword().equals(client.getPassword())){
			client = c;
			logged = true;
			messagesPage.add("Identification effectuee");
			messagesPage.add("Bonjour "+client.getNom());
			return "accueil";
		}else {
			logged = false;
			messagesErr.add("Identification impossible");
			messagesErr.add("Veuillez corriger le formulaire");
			return "identification";
		}
	}
	
	public String listerVoyages() {
		voyages = Base.listerVoyages(sessionHibernate);
		return "listerVoyages";
	}
	
	public String commander() {
		System.out.println("commander");
		
		
		
		return null;
	}
	
	
	public ArrayList <String> getMessagesPage() {
		System.out.println("getMessagesPage");
		ArrayList <String> mess = messagesPage;
		messagesPage = new ArrayList<String>();
		return mess;
	}

	public int getMessagesPageSize() {
		return messagesPage.size();
	}

	public void setMessagesPage(ArrayList <String> messages) {
		this.messagesPage = messages;
	}

	public ArrayList <String> getMessagesErr() {
		System.out.println("getMessagesErr");
		ArrayList <String> mess = messagesErr;
		messagesErr = new ArrayList<String>();
		return mess;
	}

	public int getMessagesErrSize() {
		return messagesErr.size();
	}

	public void setMessagesErr(ArrayList <String> messages) {
		this.messagesErr = messages;
	}

	public boolean isLogged() {
		return logged;
	}

	public String getErr() {
		String err2 = err;
		err = "";
		return err2;
	}

	public Client getClient() {
		return client;
	}

	public void setClient(Client client) {
		this.client = client;
	}


	public List<Voyage> getVoyages() {
		return voyages;
	}


	public void setVoyages(List<Voyage> voyages) {
		this.voyages = voyages;
	}

	public List<String> getSrceVilles() {
		return srceVilles;
	}

	public void setSrceVilles(List<String> srceVilles) {
		this.srceVilles = srceVilles;
	}

	public List<String> getDestVilles() {
		return destVilles;
	}

	public void setDestVilles(List<String> destVilles) {
		this.destVilles = destVilles;
	}

	public Integer getIdVoyage() {
		return idVoyage;
	}

	public void setIdVoyage(Integer idVoyage) {
		this.idVoyage = idVoyage;
	}











	
}